package com.etc.delivery.service.driver.impl;


import com.etc.delivery.dao.driver.IDriverDao1;
import com.etc.delivery.dto.DriverDto;
import com.etc.delivery.entity.Driver;
import com.etc.delivery.entity.Warehouse;
import com.etc.delivery.entity.Waybill;
import com.etc.delivery.service.driver.IDriverService1;
import com.etc.delivery.utils.MD5Utils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("DriverServiceImpl3")
public class DriverServiceImpl1 implements IDriverService1 {

    @Resource
    private IDriverDao1 iDriverDao;

    @Override
    public List<Driver> checkPhone(String phone) {

        return iDriverDao.checkPhone(phone);
    }

    @Override
    public boolean register(Driver driver) {
        driver.setPassword(MD5Utils.getPWD(driver.getPassword()));
        return iDriverDao.register(driver);
    }

    @Override
    public List<Driver> DriverLogin(String phone, String password) {
        List<Driver> list = iDriverDao.DriverLogin(phone, MD5Utils.getPWD(password));


        return list;
    }

    @Override
    public List<Waybill> queryAllWaybill() {
//        return iDriverDao.queryAllWaybill();
        return null;
    }

    @Override
    public PageInfo<Waybill> queryAllWaybillByPage(int pageNum, int pageSize, Integer warehouseId) {
        PageHelper.startPage(pageNum, pageSize);

        List<Waybill> wlist = iDriverDao.queryAllWaybill(warehouseId);

        PageInfo<Waybill> pageInfo = new PageInfo<Waybill>(wlist);

        return pageInfo;
    }

    @Override
    public PageInfo<Waybill> queryAllWaybillByPage1(int pageNum, int pageSize, Integer warehouseId) {
        PageHelper.startPage(pageNum, pageSize);

        List<Waybill> wlist = iDriverDao.queryAllWaybill1(warehouseId);

        PageInfo<Waybill> pageInfo = new PageInfo<Waybill>(wlist);

        return pageInfo;
    }

    @Override
    public String getPasswordByPhone(String phone) {
        return iDriverDao.queryDriverByPhone(phone).getPhone();
    }

    @Override
    public boolean modifyPassword(String phone, String newpassword) {
        Driver driver = iDriverDao.queryDriverByPhone(phone);
        driver.setPhone(phone);
        driver.setPassword(MD5Utils.getPWD(newpassword));
        boolean flag = iDriverDao.modifyPassword(driver);
        return flag;

    }

    @Override
    public Driver queryDriverByPhone(String phone) {
        return iDriverDao.queryDriverByPhone(phone);
    }

    @Override
    public boolean modifyDriver(Driver driver) {
        return iDriverDao.modifyDriver(driver);
    }

    @Override
    public boolean modifyWaybillStatus(String waybillNo, Integer driverId, Integer warehouseId) {
        return iDriverDao.modifyWaybillStatus(waybillNo, driverId, warehouseId);
    }

    @Override
    public boolean modifyWaybillStatus1(String waybillNo, Integer driverId) {
        return iDriverDao.modifyWaybillStatus1(waybillNo, driverId);
    }

    @Override
    public PageInfo<Waybill> queryWaybillStatusByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);

        List<Waybill> wlist = iDriverDao.queryWaybillByStatus();

        PageInfo<Waybill> pageInfo = new PageInfo<Waybill>(wlist);

        return pageInfo;
    }

    @Override
    public PageInfo<Waybill> queryWaybillStatus1ByPage(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);

        List<Waybill> wlist = iDriverDao.queryWaybillByStatus1();

        PageInfo<Waybill> pageInfo = new PageInfo<Waybill>(wlist);

        return pageInfo;
    }


    @Override
    public PageInfo<Waybill> queryWaybillByDriverId(int pageNum, int pageSize, Integer id) {
        PageHelper.startPage(pageNum, pageSize);

        List<Waybill> wlist = iDriverDao.queryWaybillByDriverId(id);

        PageInfo<Waybill> pageInfo = new PageInfo<Waybill>(wlist);

        return pageInfo;
    }

    @Override
    public boolean arrived(String waybillNo) {
        return iDriverDao.arrived(waybillNo);
    }

    @Override
    public boolean changeDriverWaybillStatus(String status) {
        return iDriverDao.changeDriverWaybillStatus(status);
    }

    @Override
    public List<DriverDto> queryMyInfo(Integer id) {
        return iDriverDao.queryMyInfo(id);
    }

    @Override
    public List<Warehouse> queryWareName() {
        return iDriverDao.queryWareName();
    }

    @Override
    public String getPassword(String phone) {
        return iDriverDao.getPassword(phone);
    }

    @Override
    public boolean checkEmail(String email, String phone) {

        List<Driver> list = iDriverDao.checkEmail(email, phone);

        return !list.isEmpty();
    }


}
